package proc

import (
	"common"
	"encoding/json"
	"fmt"
	"net"
	"utils"
)

type SmsProc struct {

}

func (this *SmsProc) SendGroupMessage(mes *common.Message) (err error) {
	var smsMes common.SmsMes
	if err = json.Unmarshal([]byte(mes.Data), &smsMes); err != nil {
		fmt.Println("SendGroupMessage json unmarshal err", err)
		return err
	}

	for id, val := range onlineUsers.onlineUsers {
		if id == smsMes.UserId {
			continue
		}
		this.SendMessage(mes,val.Conn)
	}
	return
}

func (this *SmsProc) SendMessage(mes *common.Message, conn net.Conn) {
	ut := &utils.Utils{
		Conn: conn,
	}
	ut.WriteMes(mes)
}
